package cn.nju.zyy.action.person;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.nju.zyy.model.person.Person;
import cn.nju.zyy.model.person.State;
import cn.nju.zyy.service.person.EditService;

import com.opensymphony.xwork2.ActionSupport;

@Component
public class EditAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private EditService editService;
	
	private Person person;
	private String[] sports = { "football", "baseball", "basketball" };
	private String[] genders = { "male", "female", "not sure" };
	private List<State> states;
	private String[] carModelsAvailable = { "Ford", "Chrysler", "Toyota",
			"Nissan" };

	@Override
	@Action("edit-input")
	public String input() throws Exception {
		setPerson(editService.getPerson());
		return INPUT;
	}

	@Override
	public String execute() throws Exception {
		editService.savePerson(person);
		return SUCCESS;
	}

	@Autowired
	public void setEditService(EditService editService) {
		this.editService = editService;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public String[] getSports() {
		return sports;
	}

	public String[] getGenders() {
		return genders;
	}

	public List<State> getStates() {
		if (states == null) {
			states = new ArrayList<State>();
			states.add(new State("AZ", "Arizona"));
			states.add(new State("CA", "California"));
			states.add(new State("FL", "Florida"));
			states.add(new State("KS", "Kansas"));
			states.add(new State("NY", "New York"));
		}
		return states;
	}

	public String[] getCarModelsAvailable() {
		return carModelsAvailable;
	}

}
